home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / widget / nsIWidget.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  34KB  |  1,051 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #ifndef nsIWidget_h__
  39. #define nsIWidget_h__
  40.  
  41. #include "nsISupports.h"
  42. #include "nsColor.h"
  43. #include "nsIMouseListener.h"
  44. #include "nsIMenuListener.h"
  45. #include "nsCoord.h"
  46.  
  47. #include "prthread.h"
  48. #include "nsEvent.h"
  49. #include "nsCOMPtr.h"
  50.  
  51. // forward declarations
  52. class   nsIAppShell;
  53. class   nsIToolkit;
  54. class   nsIFontMetrics;
  55. class   nsIToolkit;
  56. class   nsIRenderingContext;
  57. class   nsIEnumerator;
  58. class   nsIDeviceContext;
  59. class   nsIRegion;
  60. struct  nsRect;
  61. struct  nsFont;
  62. class   nsIMenuBar;
  63. class   nsIEventListener;
  64. class   nsIRollupListener;
  65. class   nsGUIEvent;
  66. struct  nsColorMap;
  67. class   imgIContainer;
  68.  
  69. /**
  70.  * Callback function that processes events.
  71.  * The argument is actually a subtype (subclass) of nsEvent which carries
  72.  * platform specific information about the event. Platform specific code knows
  73.  * how to deal with it.
  74.  * The return value determines whether or not the default action should take place.
  75.  */
  76.  
  77. typedef nsEventStatus (*PR_CALLBACK EVENT_CALLBACK)(nsGUIEvent *event);
  78.  
  79. /**
  80.  * Flags for the getNativeData function.
  81.  * See getNativeData()
  82.  */
  83. #define NS_NATIVE_WINDOW      0
  84. #define NS_NATIVE_GRAPHIC     1
  85. #define NS_NATIVE_COLORMAP    2
  86. #define NS_NATIVE_WIDGET      3
  87. #define NS_NATIVE_DISPLAY     4
  88. #define NS_NATIVE_REGION      5
  89. #define NS_NATIVE_OFFSETX     6
  90. #define NS_NATIVE_OFFSETY     7
  91. #define NS_NATIVE_PLUGIN_PORT 8
  92. #define NS_NATIVE_SCREEN      9
  93. #define NS_NATIVE_SHELLWIDGET 10      // Get the shell GtkWidget
  94.  
  95. // e7f09105-d21b-406a-89d5-e6b731b8f665
  96. #define NS_IWIDGET_IID \
  97. { 0xe7f09105, 0xd21b, 0x406a, \
  98.   { 0x89, 0xd5, 0xe6, 0xb7, 0x31, 0xb8, 0xf6, 0x65 } }
  99.  
  100.  
  101. // Hide the native window systems real window type so as to avoid
  102. // including native window system types and api's. This is necessary
  103. // to ensure cross-platform code.
  104. typedef void* nsNativeWidget;
  105.  
  106. /**
  107.  * Border styles
  108.  */
  109.  
  110. enum nsWindowType {     // Don't alter previously encoded enum values - 3rd party apps may look at these
  111.   // default top level window
  112.   eWindowType_toplevel,
  113.   // top level window but usually handled differently by the OS
  114.   eWindowType_dialog,
  115.   // used for combo boxes, etc
  116.   eWindowType_popup,
  117.   // child windows (contained inside a window on the desktop (has no border))
  118.   eWindowType_child,
  119.   // windows that are invisible or offscreen
  120.   eWindowType_invisible,
  121.   // plugin window
  122.   eWindowType_plugin,
  123.   // java plugin window
  124.   eWindowType_java,
  125.   // MacOSX sheet (special dialog class)
  126.   eWindowType_sheet
  127. };
  128.  
  129. enum nsBorderStyle
  130. {
  131.   // no border, titlebar, etc.. opposite of all
  132.   eBorderStyle_none     = 0,
  133.  
  134.   // all window decorations
  135.   eBorderStyle_all      = 1 << 0,
  136.  
  137.   // enables the border on the window.  these are only for decoration and are not resize hadles
  138.   eBorderStyle_border   = 1 << 1,
  139.  
  140.   // enables the resize handles for the window.  if this is set, border is implied to also be set
  141.   eBorderStyle_resizeh  = 1 << 2,
  142.  
  143.   // enables the titlebar for the window
  144.   eBorderStyle_title    = 1 << 3,
  145.  
  146.   // enables the window menu button on the title bar.  this being on should force the title bar to display
  147.   eBorderStyle_menu     = 1 << 4,
  148.  
  149.   // enables the minimize button so the user can minimize the window.
  150.   //   turned off for tranient windows since they can not be minimized separate from their parent
  151.   eBorderStyle_minimize = 1 << 5,
  152.  
  153.   // enables the maxmize button so the user can maximize the window
  154.   eBorderStyle_maximize = 1 << 6,
  155.  
  156.   // show the close button
  157.   eBorderStyle_close    = 1 << 7,
  158.  
  159.   // whatever the OS wants... i.e. don't do anything
  160.   eBorderStyle_default  = -1
  161. };
  162.  
  163. /**
  164.  * Cursor types.
  165.  */
  166.  
  167. enum nsCursor {   ///(normal cursor,       usually rendered as an arrow)
  168.                 eCursor_standard, 
  169.                   ///(system is busy,      usually rendered as a hourglass or watch)
  170.                 eCursor_wait, 
  171.                   ///(Selecting something, usually rendered as an IBeam)
  172.                 eCursor_select, 
  173.                   ///(can hyper-link,      usually rendered as a human hand)
  174.                 eCursor_hyperlink, 
  175.                   ///(north/south/west/east edge sizing)
  176.                 eCursor_n_resize,
  177.                 eCursor_s_resize,
  178.                 eCursor_w_resize,
  179.                 eCursor_e_resize,
  180.                   ///(corner sizing)
  181.                 eCursor_nw_resize,
  182.                 eCursor_se_resize,
  183.                 eCursor_ne_resize,
  184.                 eCursor_sw_resize,
  185.                 eCursor_crosshair,
  186.                 eCursor_move,
  187.                 eCursor_help,
  188.                 eCursor_copy, // CSS3
  189.                 eCursor_alias,
  190.                 eCursor_context_menu,
  191.                 eCursor_cell,
  192.                 eCursor_grab,
  193.                 eCursor_grabbing,
  194.                 eCursor_spinning,
  195.                 eCursor_zoom_in,
  196.                 eCursor_zoom_out,
  197.                 eCursor_not_allowed,
  198.                 eCursor_col_resize,
  199.                 eCursor_row_resize,
  200.                 eCursor_no_drop,
  201.                 eCursor_vertical_text,
  202.                 eCursor_all_scroll,
  203.                 eCursor_nesw_resize,
  204.                 eCursor_nwse_resize,
  205.                 eCursor_ns_resize,
  206.                 eCursor_ew_resize,
  207.                 // This one better be the last one in this list.
  208.                 eCursorCount
  209.                 }; 
  210.  
  211. enum nsContentType {
  212.   eContentTypeInherit = -1,
  213.   eContentTypeUI = 0,
  214.   eContentTypeContent = 1,
  215.   eContentTypeContentFrame = 2
  216. };
  217.  
  218. enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
  219.   eZPlacementBottom = 0,  // bottom of the window stack
  220.   eZPlacementBelow,       // just below another widget
  221.   eZPlacementTop          // top of the window stack
  222. };
  223.  
  224. /**
  225.  * Basic struct for widget initialization data.
  226.  * @see Create member function of nsIWidget
  227.  */
  228.  
  229. struct nsWidgetInitData {
  230.   nsWidgetInitData()
  231.     : clipChildren(PR_FALSE), 
  232.       clipSiblings(PR_FALSE), 
  233.       mDropShadow(PR_FALSE),
  234.       mListenForResizes(PR_FALSE),
  235.       mWindowType(eWindowType_child),
  236.       mBorderStyle(eBorderStyle_default),
  237.       mContentType(eContentTypeInherit),
  238.       mUnicode(PR_TRUE)
  239.   {
  240.   }
  241.  
  242.   // when painting exclude area occupied by child windows and sibling windows
  243.   PRPackedBool  clipChildren, clipSiblings, mDropShadow;
  244.   PRPackedBool  mListenForResizes;
  245.   nsWindowType mWindowType;
  246.   nsBorderStyle mBorderStyle;
  247.   nsContentType mContentType;  // Exposed so screen readers know what's UI
  248.   PRPackedBool mUnicode;
  249. };
  250.  
  251. /**
  252.  * The base class for all the widgets. It provides the interface for
  253.  * all basic and necessary functionality.
  254.  */
  255. class nsIWidget : public nsISupports {
  256.  
  257.   public:
  258.  
  259.     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
  260.  
  261.     nsIWidget()
  262.       : mLastChild(nsnull)
  263.       , mPrevSibling(nsnull)
  264.     {}
  265.  
  266.         
  267.     /**
  268.      * Create and initialize a widget. 
  269.      *
  270.      * The widget represents a window that can be drawn into. It also is the 
  271.      * base class for user-interface widgets such as buttons and text boxes.
  272.      *
  273.      * All the arguments can be NULL in which case a top level window
  274.      * with size 0 is created. The event callback function has to be
  275.      * provided only if the caller wants to deal with the events this
  276.      * widget receives.  The event callback is basically a preprocess
  277.      * hook called synchronously. The return value determines whether
  278.      * the event goes to the default window procedure or it is hidden
  279.      * to the os. The assumption is that if the event handler returns
  280.      * false the widget does not see the event. The widget should not 
  281.      * automatically clear the window to the background color. The 
  282.      * calling code must handle paint messages and clear the background 
  283.      * itself. 
  284.      *
  285.      * aInitData cannot be eWindowType_popup here; popups cannot be
  286.      * hooked into the nsIWidget hierarchy.
  287.      *
  288.      * @param     parent or null if it's a top level window
  289.      * @param     aRect     the widget dimension
  290.      * @param     aHandleEventFunction the event handler callback function
  291.      * @param     aContext
  292.      * @param     aAppShell the parent application shell. If nsnull,
  293.      *                      the parent window's application shell will be used.
  294.      * @param     aToolkit
  295.      * @param     aInitData data that is used for widget initialization
  296.      *
  297.      */
  298.     NS_IMETHOD Create(nsIWidget        *aParent,
  299.                         const nsRect     &aRect,
  300.                         EVENT_CALLBACK   aHandleEventFunction,
  301.                         nsIDeviceContext *aContext,
  302.                         nsIAppShell      *aAppShell = nsnull,
  303.                         nsIToolkit       *aToolkit = nsnull,
  304.                         nsWidgetInitData *aInitData = nsnull) = 0;
  305.  
  306.     /**
  307.      * Create and initialize a widget with a native window parent
  308.      *
  309.      * The widget represents a window that can be drawn into. It also is the 
  310.      * base class for user-interface widgets such as buttons and text boxes.
  311.      *
  312.      * All the arguments can be NULL in which case a top level window
  313.      * with size 0 is created. The event callback function has to be
  314.      * provided only if the caller wants to deal with the events this
  315.      * widget receives.  The event callback is basically a preprocess
  316.      * hook called synchronously. The return value determines whether
  317.      * the event goes to the default window procedure or it is hidden
  318.      * to the os. The assumption is that if the event handler returns
  319.      * false the widget does not see the event.
  320.      *
  321.      * @param     aParent   native window.
  322.      * @param     aRect     the widget dimension
  323.      * @param     aHandleEventFunction the event handler callback function
  324.      */
  325.     NS_IMETHOD Create(nsNativeWidget aParent,
  326.                         const nsRect     &aRect,
  327.                         EVENT_CALLBACK   aHandleEventFunction,
  328.                         nsIDeviceContext *aContext,
  329.                         nsIAppShell      *aAppShell = nsnull,
  330.                         nsIToolkit       *aToolkit = nsnull,
  331.                         nsWidgetInitData *aInitData = nsnull) = 0;
  332.  
  333.  
  334.     /**
  335.      * Accessor functions to get and set the client data associated with the
  336.      * widget.
  337.      */
  338.     //@{
  339.     NS_IMETHOD  GetClientData(void*& aClientData) = 0;
  340.     NS_IMETHOD  SetClientData(void* aClientData) = 0;
  341.     //@}
  342.  
  343.     /**
  344.      * Close and destroy the internal native window. 
  345.      * This method does not delete the widget.
  346.      */
  347.  
  348.     NS_IMETHOD Destroy(void) = 0;
  349.  
  350.  
  351.     /**
  352.      * Reparent a widget
  353.      *
  354.      * Change the widgets parent
  355.      *
  356.      * @param     aNewParent   new parent 
  357.      */
  358.     NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
  359.  
  360.  
  361.     /**
  362.      * Return the parent Widget of this Widget or nsnull if this is a 
  363.      * top level window
  364.      *
  365.      * @return the parent widget or nsnull if it does not have a parent
  366.      *
  367.      */
  368.     virtual nsIWidget* GetParent(void) = 0;
  369.  
  370.     /**
  371.      * Return the first child of this widget.  Will return null if
  372.      * there are no children.
  373.      */
  374.     nsIWidget* GetFirstChild() const {
  375.         return mFirstChild;
  376.     }
  377.     
  378.     /**
  379.      * Return the last child of this widget.  Will return null if
  380.      * there are no children.
  381.      */
  382.     nsIWidget* GetLastChild() const {
  383.         return mLastChild;
  384.     }
  385.  
  386.     /**
  387.      * Return the next sibling of this widget
  388.      */
  389.     nsIWidget* GetNextSibling() const {
  390.         return mNextSibling;
  391.     }
  392.     
  393.     /**
  394.      * Set the next sibling of this widget
  395.      */
  396.     void SetNextSibling(nsIWidget* aSibling) {
  397.         mNextSibling = aSibling;
  398.     }
  399.     
  400.     /**
  401.      * Return the previous sibling of this widget
  402.      */
  403.     nsIWidget* GetPrevSibling() const {
  404.         return mPrevSibling;
  405.     }
  406.  
  407.     /**
  408.      * Set the previous sibling of this widget
  409.      */
  410.     void SetPrevSibling(nsIWidget* aSibling) {
  411.         mPrevSibling = aSibling;
  412.     }
  413.  
  414.     /**
  415.      * Show or hide this widget
  416.      *
  417.      * @param aState PR_TRUE to show the Widget, PR_FALSE to hide it
  418.      *
  419.      */
  420.     NS_IMETHOD Show(PRBool aState) = 0;
  421.  
  422.     /**
  423.      * Make the window modal
  424.      *
  425.      */
  426.     NS_IMETHOD SetModal(PRBool aModal) = 0;
  427.  
  428.     /**
  429.      * Returns whether the window is visible
  430.      *
  431.      */
  432.     NS_IMETHOD IsVisible(PRBool & aState) = 0;
  433.  
  434.     /**
  435.      * Perform platform-dependent sanity check on a potential window position.
  436.      * This is guaranteed to work only for top-level windows.
  437.      *
  438.      * @param aAllowSlop: if true, allow the window to slop offscreen;
  439.      *                    the window should be partially visible. if false,
  440.      *                    force the entire window onscreen (or at least
  441.      *                    the upper-left corner, if it's too large).
  442.      * @param aX in: an x position expressed in screen coordinates.
  443.      *           out: the x position constrained to fit on the screen(s).
  444.      * @param aY in: an y position expressed in screen coordinates.
  445.      *           out: the y position constrained to fit on the screen(s).
  446.      * @return vapid success indication. but see also the parameters.
  447.      *
  448.      **/
  449.     NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
  450.                                  PRInt32 *aX,
  451.                                  PRInt32 *aY) = 0;
  452.  
  453.     /**
  454.      * Move this widget.
  455.      *
  456.      * @param aX the new x position expressed in the parent's coordinate system
  457.      * @param aY the new y position expressed in the parent's coordinate system
  458.      *
  459.      **/
  460.     NS_IMETHOD Move(PRInt32 aX, PRInt32 aY) = 0;
  461.  
  462.     /**
  463.      * Resize this widget. 
  464.      *
  465.      * @param aWidth  the new width expressed in the parent's coordinate system
  466.      * @param aHeight the new height expressed in the parent's coordinate system
  467.      * @param aRepaint whether the widget should be repainted
  468.      *
  469.      */
  470.     NS_IMETHOD Resize(PRInt32 aWidth,
  471.                       PRInt32 aHeight,
  472.                       PRBool   aRepaint) = 0;
  473.  
  474.     /**
  475.      * Move or resize this widget.
  476.      *
  477.      * @param aX       the new x position expressed in the parent's coordinate system
  478.      * @param aY       the new y position expressed in the parent's coordinate system
  479.      * @param aWidth   the new width expressed in the parent's coordinate system
  480.      * @param aHeight  the new height expressed in the parent's coordinate system
  481.      * @param aRepaint whether the widget should be repainted if the size changes
  482.      *
  483.      */
  484.     NS_IMETHOD Resize(PRInt32 aX,
  485.                       PRInt32 aY,
  486.                       PRInt32 aWidth,
  487.                       PRInt32 aHeight,
  488.                       PRBool   aRepaint) = 0;
  489.  
  490.     /**
  491.      * Sets the widget's z-index.
  492.      */
  493.     NS_IMETHOD SetZIndex(PRInt32 aZIndex) = 0;
  494.  
  495.     /**
  496.      * Gets the widget's z-index. 
  497.      */
  498.     NS_IMETHOD GetZIndex(PRInt32* aZIndex) = 0;
  499.  
  500.     /**
  501.      * Position this widget just behind the given widget. (Used to
  502.      * control z-order for top-level widgets. Get/SetZIndex by contrast
  503.      * control z-order for child widgets of other widgets.)
  504.      * @param aPlacement top, bottom, or below a widget
  505.      *                   (if top or bottom, param aWidget is ignored)
  506.      * @param aWidget    widget to place this widget behind
  507.      *                   (only if aPlacement is eZPlacementBelow).
  508.      *                   null is equivalent to aPlacement of eZPlacementTop
  509.      * @param aActivate  true to activate the widget after placing it
  510.      */
  511.     NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
  512.                            nsIWidget *aWidget, PRBool aActivate) = 0;
  513.  
  514.     /**
  515.      * Minimize, maximize or normalize the window size.
  516.      * Takes a value from nsSizeMode (see nsGUIEvent.h)
  517.      */
  518.     NS_IMETHOD SetSizeMode(PRInt32 aMode) = 0;
  519.  
  520.     /**
  521.      * Return size mode (minimized, maximized, normalized).
  522.      * Returns a value from nsSizeMode (see nsGUIEvent.h)
  523.      */
  524.     NS_IMETHOD GetSizeMode(PRInt32* aMode) = 0;
  525.  
  526.     /**
  527.      * Enable or disable this Widget
  528.      *
  529.      * @param aState PR_TRUE to enable the Widget, PR_FALSE to disable it.
  530.      *
  531.      */
  532.     NS_IMETHOD Enable(PRBool aState) = 0;
  533.  
  534.     /**
  535.      * Ask whether the widget is enabled
  536.      * @param aState returns PR_TRUE if the widget is enabled
  537.      */
  538.     NS_IMETHOD IsEnabled(PRBool *aState) = 0;
  539.  
  540.     /**
  541.      * Give focus to this widget.
  542.      */
  543.     NS_IMETHOD SetFocus(PRBool aRaise = PR_FALSE) = 0;
  544.  
  545.     /**
  546.      * Get this widget's outside dimensions relative to its parent widget
  547.      *
  548.      * @param aRect on return it holds the  x, y, width and height of this widget
  549.      *
  550.      */
  551.     NS_IMETHOD GetBounds(nsRect &aRect) = 0;
  552.  
  553.  
  554.     /**
  555.      * Get this widget's outside dimensions in global coordinates. (One might think this
  556.      * could be accomplished by stringing together other methods in this interface, but
  557.      * then one would bloody one's nose on different coordinate system handling by different
  558.      * platforms.)
  559.      *
  560.      * @param aRect on return it holds the  x, y, width and height of this widget
  561.      *
  562.      */
  563.     NS_IMETHOD GetScreenBounds(nsRect &aRect) = 0;
  564.  
  565.  
  566.     /**
  567.      * Get this widget's client area dimensions, if the window has a 3D border appearance
  568.      * this returns the area inside the border, The x and y are always zero
  569.      *
  570.      * @param aRect on return it holds the  x. y, width and height of the client area of this widget
  571.      *
  572.      */
  573.     NS_IMETHOD GetClientBounds(nsRect &aRect) = 0;
  574.  
  575.     /**
  576.      * Gets the width and height of the borders
  577.      * @param aWidth the width of the border
  578.      * @param aHeight the height of the border
  579.      *
  580.      */
  581.     NS_IMETHOD GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight) = 0;
  582.  
  583.     /**
  584.      * Get the foreground color for this widget
  585.      *
  586.      * @return this widget's foreground color
  587.      *
  588.      */
  589.     virtual nscolor GetForegroundColor(void) = 0;
  590.  
  591.     /**
  592.      * Set the foreground color for this widget
  593.      *
  594.      * @param aColor the new foreground color
  595.      *
  596.      */
  597.  
  598.     NS_IMETHOD SetForegroundColor(const nscolor &aColor) = 0;
  599.  
  600.     /**
  601.      * Get the background color for this widget
  602.      *
  603.      * @return this widget's background color
  604.      *
  605.      */
  606.  
  607.     virtual nscolor GetBackgroundColor(void) = 0;
  608.  
  609.     /**
  610.      * Set the background color for this widget
  611.      *
  612.      * @param aColor the new background color
  613.      *
  614.      */
  615.  
  616.     NS_IMETHOD SetBackgroundColor(const nscolor &aColor) = 0;
  617.  
  618.     /**
  619.      * Get the font for this widget
  620.      *
  621.      * @return the font metrics 
  622.      */
  623.  
  624.     virtual nsIFontMetrics* GetFont(void) = 0;
  625.  
  626.     /**
  627.      * Set the font for this widget 
  628.      *
  629.      * @param aFont font to display. See nsFont for allowable fonts
  630.      */
  631.  
  632.     NS_IMETHOD SetFont(const nsFont &aFont) = 0;
  633.  
  634.     /**
  635.      * Get the cursor for this widget.
  636.      *
  637.      * @return this widget's cursor.
  638.      */
  639.  
  640.     virtual nsCursor GetCursor(void) = 0;
  641.  
  642.     /**
  643.      * Set the cursor for this widget
  644.      *
  645.      * @param aCursor the new cursor for this widget
  646.      */
  647.  
  648.     NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
  649.  
  650.     /**
  651.      * Sets an image as the cursor for this widget.
  652.      *
  653.      * @param aCursor the cursor to set
  654.      * @param aX the X coordinate of the hotspot (from left).
  655.      * @param aY the Y coordinate of the hotspot (from top).
  656.      * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
  657.      *         supported
  658.      */
  659.     NS_IMETHOD SetCursor(imgIContainer* aCursor,
  660.                          PRUint32 aHotspotX, PRUint32 aHotspotY) = 0;
  661.  
  662.     /** 
  663.      * Get the window type of this widget
  664.      *
  665.      * @param aWindowType the window type of the widget
  666.      */
  667.     NS_IMETHOD GetWindowType(nsWindowType& aWindowType) = 0;
  668.  
  669.     /**
  670.      * Set the translucency of the top-level window containing this widget.
  671.      * So, e.g., if you call this on the widget for an IFRAME, the top level
  672.      * browser window containing the IFRAME actually gets set. Be careful.
  673.      *
  674.      * This can fail if the platform doesn't support
  675.      * transparency/translucency. By default widgets are not
  676.      * transparent.  This will also fail if the toplevel window is not
  677.      * a Mozilla window, e.g., if the widget is in an embedded
  678.      * context.
  679.      *
  680.      * After translucency has been enabled, the initial alpha channel
  681.      * value for all pixels is 1, i.e., opaque.
  682.      * If the window is resized then the alpha channel values for
  683.      * all pixels are reset to 1.
  684.      * @param aTranslucent true if the window may have translucent
  685.      *   or transparent pixels
  686.      */
  687.     NS_IMETHOD SetWindowTranslucency(PRBool aTranslucent) = 0;
  688.  
  689.     /**
  690.      * Get the translucency of the top-level window that contains this
  691.      * widget.
  692.      * @param aTranslucent true if the window may have translucent or
  693.      *   transparent pixels
  694.      */
  695.     NS_IMETHOD GetWindowTranslucency(PRBool& aTranslucent) = 0;
  696.  
  697.     /**
  698.      * Update the alpha channel for some pixels of the top-level window
  699.      * that contains this widget.
  700.      * The window must have been made translucent using SetWindowTranslucency.
  701.      * @param aRect the rect to update
  702.      * @param aAlphas the alpha values, in w x h array, row-major order,
  703.      * in units of 1/255. nsBlender::GetAlphas is a good way to compute this array.
  704.      */
  705.     NS_IMETHOD UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas) = 0;
  706.  
  707.     /** 
  708.      * Hide window chrome (borders, buttons) for this widget.
  709.      *
  710.      */
  711.     NS_IMETHOD HideWindowChrome(PRBool aShouldHide) = 0;
  712.  
  713.     /**
  714.      * Put the toplevel window into or out of fullscreen mode.
  715.      *
  716.      */
  717.     NS_IMETHOD MakeFullScreen(PRBool aFullScreen) = 0;
  718.  
  719.     /**
  720.      * Validate the widget.
  721.      *
  722.      */
  723.     NS_IMETHOD Validate() = 0;
  724.  
  725.     /**
  726.      * Invalidate the widget and repaint it.
  727.      *
  728.      * @param aIsSynchronous PR_TRUE then repaint synchronously. If PR_FALSE repaint later.
  729.      * @see #Update()
  730.      */
  731.  
  732.     NS_IMETHOD Invalidate(PRBool aIsSynchronous) = 0;
  733.  
  734.     /**
  735.      * Invalidate a specified rect for a widget and repaints it.
  736.      *
  737.      * @param aIsSynchronouse PR_TRUE then repaint synchronously. If PR_FALSE repaint later.
  738.      * @see #Update()
  739.      */
  740.  
  741.     NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous) = 0;
  742.  
  743.     /**
  744.      * Invalidate a specified region for a widget and repaints it.
  745.      *
  746.      * @param aIsSynchronouse PR_TRUE then repaint synchronously. If PR_FALSE repaint later.
  747.      * @see #Update()
  748.      */
  749.  
  750.     NS_IMETHOD InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous) = 0;
  751.  
  752.     /**
  753.      * Force a synchronous repaint of the window if there are dirty rects.
  754.      *
  755.      * @see Invalidate()
  756.      */
  757.  
  758.      NS_IMETHOD Update() = 0;
  759.  
  760.     /**
  761.      * Adds a mouse listener to this widget
  762.      * Any existing mouse listener is replaced
  763.      *
  764.      * @param aListener mouse listener to add to this widget.
  765.      */
  766.  
  767.     NS_IMETHOD AddMouseListener(nsIMouseListener * aListener) = 0;
  768.  
  769.     /**
  770.      * Adds an event listener to this widget
  771.      * Any existing event listener is replaced
  772.      *
  773.      * @param aListener event listener to add to this widget.
  774.      */
  775.  
  776.     NS_IMETHOD AddEventListener(nsIEventListener * aListener) = 0;
  777.  
  778.     /**
  779.      * Adds a menu listener to this widget
  780.      * Any existing menu listener is replaced
  781.      *
  782.      * @param aListener menu listener to add to this widget.
  783.      */
  784.  
  785.     NS_IMETHOD AddMenuListener(nsIMenuListener * aListener) = 0;
  786.     
  787.     /**
  788.      * Return the widget's toolkit
  789.      *
  790.      * @return the toolkit this widget was created in. See nsToolkit.
  791.      */
  792.  
  793.     virtual nsIToolkit* GetToolkit() = 0;    
  794.  
  795.     /**
  796.      * Set the color map for this widget
  797.      *
  798.      * @param aColorMap color map for displaying this widget
  799.      *
  800.      */
  801.  
  802.     NS_IMETHOD SetColorMap(nsColorMap *aColorMap) = 0;
  803.  
  804.     /**
  805.      * XXX (This is obsolete and will be removed soon, Use ScrollWidgets instead)
  806.      * Scroll this widget. 
  807.      *
  808.      * @param aDx amount to scroll along the x-axis
  809.      * @param aDy amount to scroll along the y-axis.
  810.      * @param aClipRect clipping rectangle to limit the scroll to.
  811.      *
  812.      */
  813.  
  814.     NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) = 0;
  815.  
  816.     /**
  817.      * Scroll the contents of the widget. 
  818.      * All child widgets are also scrolled by offsetting their coordinates.
  819.      * A NS_PAINT message is synchronously dispatched for the newly exposed rectangle.
  820.      *
  821.      * @param aDx amount to scroll along the x-axis in pixels
  822.      * @param aDy amount to scroll along the y-axis in pixels
  823.      *
  824.      */
  825.  
  826.     NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy) = 0;
  827.  
  828.     /**
  829.      * Scroll an area of this widget. Child widgets are not scrolled.
  830.      * A NS_PAINT message is synchronously dispatched for the newly exposed rectangle.
  831.      *
  832.      * @param aRect source rectangle to scroll in the widget in pixels
  833.      * @param aDx x offset from the source in pixels
  834.      * @param aDy y offset from the source in pixels
  835.      *
  836.      */
  837.  
  838.     NS_IMETHOD ScrollRect(nsRect &aSrcRect, PRInt32 aDx, PRInt32 aDy) = 0;
  839.  
  840.     /** 
  841.      * Internal methods
  842.      */
  843.  
  844.     //@{
  845.     virtual void AddChild(nsIWidget* aChild) = 0;
  846.     virtual void RemoveChild(nsIWidget* aChild) = 0;
  847.     virtual void* GetNativeData(PRUint32 aDataType) = 0;
  848.     virtual void FreeNativeData(void * data, PRUint32 aDataType) = 0;//~~~
  849.     virtual nsIRenderingContext* GetRenderingContext() = 0;
  850.     virtual nsIDeviceContext* GetDeviceContext() = 0;
  851.     virtual nsIAppShell *GetAppShell() = 0;
  852.     //@}
  853.  
  854.     /**
  855.      * Set border style
  856.      * Must be called before Create.
  857.      * @param aBorderStyle @see nsBorderStyle
  858.      */
  859.  
  860.     NS_IMETHOD SetBorderStyle(nsBorderStyle aBorderStyle) = 0;
  861.  
  862.     /**
  863.      * Set the widget's title.
  864.      * Must be called after Create.
  865.      *
  866.      * @param aTitle string displayed as the title of the widget
  867.      */
  868.  
  869.     NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
  870.  
  871.     /**
  872.      * Set the widget's icon.
  873.      * Must be called after Create.
  874.      *
  875.      * @param anIconSpec string specifying the icon to use; convention is to pass
  876.      *                   a resource: URL from which a platform-dependent resource
  877.      *                   file name will be constructed
  878.      */
  879.  
  880.     NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
  881.  
  882.     /**
  883.      * Set the widget's MenuBar.
  884.      * Must be called after Create.
  885.      *
  886.      * @param aMenuBar the menubar
  887.      */
  888.  
  889.     NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar) = 0;
  890.  
  891.     /**
  892.      * Set the widget's MenuBar's visibility
  893.      *
  894.      * @param aShow PR_TRUE to show, PR_FALSE to hide
  895.      */
  896.  
  897.     NS_IMETHOD ShowMenuBar(PRBool aShow) = 0;
  898.  
  899.     /**
  900.      * Convert from this widget coordinates to screen coordinates.
  901.      *
  902.      * @param  aOldRect  widget coordinates stored in the x,y members
  903.      * @param  aNewRect  screen coordinates stored in the x,y members
  904.      */
  905.  
  906.     NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) = 0;
  907.  
  908.     /**
  909.      * Convert from screen coordinates to this widget's coordinates.
  910.      *
  911.      * @param  aOldRect  screen coordinates stored in the x,y members
  912.      * @param  aNewRect  widget's coordinates stored in the x,y members
  913.      */
  914.  
  915.     NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) = 0;
  916.  
  917.     /**
  918.      * When adjustments are to made to a whole set of child widgets, call this
  919.      * before resizing/positioning the child windows to minimize repaints. Must
  920.      * be followed by EndResizingChildren() after child windows have been
  921.      * adjusted.
  922.      *
  923.      */
  924.  
  925.     NS_IMETHOD BeginResizingChildren(void) = 0;
  926.  
  927.     /**
  928.      * Call this when finished adjusting child windows. Must be preceded by
  929.      * BeginResizingChildren().
  930.      *
  931.      */
  932.  
  933.     NS_IMETHOD EndResizingChildren(void) = 0;
  934.  
  935.     /**
  936.      * Returns the preferred width and height for the widget
  937.      *
  938.      */
  939.     NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) = 0;
  940.  
  941.     /**
  942.      * Set the preferred width and height for the widget
  943.      *
  944.      */
  945.     NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) = 0;
  946.  
  947.     /**
  948.      * Dispatches an event to the widget
  949.      *
  950.      */
  951.     NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
  952.  
  953.  
  954.     /**
  955.      * For printing and lightweight widgets
  956.      *
  957.      */
  958.     NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
  959.                      const nsRect& aDirtyRect) = 0;
  960.    
  961.     /**
  962.      * Enables the dropping of files to a widget (XXX this is temporary)
  963.      *
  964.      */
  965.     NS_IMETHOD EnableDragDrop(PRBool aEnable) = 0;
  966.    
  967.     virtual void  ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) = 0;
  968.  
  969.     /**
  970.      * Enables/Disables system mouse capture.
  971.      * @param aCapture PR_TRUE enables mouse capture, PR_FALSE disables mouse capture 
  972.      *
  973.      */
  974.     NS_IMETHOD CaptureMouse(PRBool aCapture) = 0;
  975.  
  976.     /**
  977.      * Gets the window class
  978.      * implemented in gtk
  979.      */
  980.     NS_IMETHOD GetWindowClass(char *aClass) = 0;
  981.  
  982.     /**
  983.      * Sets the window class
  984.      * implemented in gtk
  985.      */
  986.     NS_IMETHOD SetWindowClass(char *aClass) = 0;
  987.  
  988.     /**
  989.      * Enables/Disables system capture of any and all events that would cause a
  990.      * dropdown to be rolled up, This method ignores the aConsumeRollupEvent 
  991.      * parameter when aDoCapture is FALSE
  992.      * @param aDoCapture PR_TRUE enables capture, PR_FALSE disables capture 
  993.      * @param aConsumeRollupEvent PR_TRUE consumes the rollup event, PR_FALSE dispatches rollup event
  994.      *
  995.      */
  996.     NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent) = 0;
  997.  
  998.     /**
  999.      *   Determine whether a given event should be processed assuming we are
  1000.      * the currently active modal window.
  1001.      *   Note that the exact semantics of this method are platform-dependent.
  1002.      * The Macintosh, for instance, cares deeply that this method do exactly
  1003.      * as advertised. Gtk, for instance, handles modality in a completely
  1004.      * different fashion and does little if anything with this method.
  1005.      * @param aRealEvent event is real or a null placeholder (Macintosh)
  1006.      * @param aEvent void pointer to native event structure
  1007.      * @param aForWindow return value. PR_TRUE iff event should be processed.
  1008.      */
  1009.     NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow) = 0;
  1010.  
  1011.     /**
  1012.      * Bring this window to the user's attention.  This is intended to be a more
  1013.      * gentle notification than popping the window to the top or putting up an
  1014.      * alert.  See, for example, Win32 FlashWindow or the NotificationManager on
  1015.      * the Mac.  The notification should be suppressed if the window is already
  1016.      * in the foreground and should be dismissed when the user brings this window
  1017.      * to the foreground.
  1018.      * @param aCycleCount Maximum number of times to animate the window per system 
  1019.      *                    conventions. If set to -1, cycles indefinitely until 
  1020.      *                    window is brought into the foreground.
  1021.      */
  1022.     NS_IMETHOD GetAttention(PRInt32 aCycleCount) = 0;
  1023.  
  1024.     /**
  1025.      * Get the last user input event time in milliseconds. If there are any pending
  1026.      * native toolkit input events it returns the current time. All input events are 
  1027.      * included (ie. it is *not* limited to events targeted at this nsIWidget instance.
  1028.      *
  1029.      * @param aTime Last user input time in milliseconds. This value can be used to compare
  1030.      * durations but can not be used for determining wall clock time. The value returned 
  1031.      * is platform dependent, but is compatible with the expression 
  1032.      * PR_IntervalToMicroseconds(PR_IntervalNow()).
  1033.      */
  1034.     NS_IMETHOD GetLastInputEventTime(PRUint32& aTime) = 0;
  1035.  
  1036.  
  1037. protected:
  1038.     // keep the list of children.  We also keep track of our siblings.
  1039.     // The ownership model is as follows: parent holds a strong ref to
  1040.     // the first element of the list, and each element holds a strong
  1041.     // ref to the next element in the list.  The prevsibling and
  1042.     // lastchild pointers are weak, which is fine as long as they are
  1043.     // maintained properly.
  1044.     nsCOMPtr<nsIWidget> mFirstChild;
  1045.     nsIWidget* mLastChild;
  1046.     nsCOMPtr<nsIWidget> mNextSibling;
  1047.     nsIWidget* mPrevSibling;
  1048. };
  1049.  
  1050. #endif // nsIWidget_h__
  1051.